<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('memory_limit', '1000M');
set_time_limit(0);
CONST TYPE_NORMAL = 1;
CONST TYPE_BAD = 2;
$off_type = 0;
$house_list = array();
function output_house($house_list, $off_type)
{
    foreach ($house_list as $house){
        if ($house['off_type'] == 1 ){
	    $out = json_encode($house);
            echo $house['source_url']."\t".$out."#D\n";
        }
        else if( $off_type == 1){
            $house['bad_type'] = 7;
        }
        if (!empty($house['bad_type'])){
	    $out = json_encode($house);
	    echo $house['bad_type']."\t".$house['id']."\t".$house['source_url']."\n";
            echo $house['source_url']."\t".$out."#B\n";
        }
        else{
	    $out = json_encode($house);
            echo ''."\t".$out."#N\n";
        }
    }
}

while (($line_json = fgets(STDIN)) !== false) {   //line_json=>source_url\tjson��ʽ
    $line_json = trim($line_json);
    if (empty($line_json))
    	continue;
    list ($source_url, $type, $list_json) = explode("\t", $line_json);
    if ($source_url=='broker_check'){
        list($source_url, $phone, $name, $source) = explode("\t", $line_json);
        //echo $type."\t".$list_json."#C\n";
        echo $phone."\t".$name."\t".$source."#C\n";
	    continue;
    }
    $house_info = json_decode($list_json, true);
    $type = trim($type);
    if ($house_info['off_type'] == 1 ){
	$off_type = 1;
    }
    if($lasturl != $house_info['source_url']){
	    output_house($house_list, $off_type);
        $off_type = 0;
        $lasturl = $house_info['source_url'];
	    $house_list = array();
    }
    else{
        if($off_type==0){
            $house_info['bad_type'] = 1;
	}
    }
    $house_list[] = $house_info;
}
output_house($house_list, $off_type);

        
 

